package com.cacshanghai.cac_oa_client.adapter;

import android.content.Context;
import android.os.Handler;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.TextView;

import com.cacshanghai.cac_oa_client.R;
import com.cacshanghai.cac_oa_client.beans.Leave;

import java.util.HashMap;
import java.util.List;

/**
 * Created by geyh on 2016/5/27.
 */
public class LeaveAdapter extends BaseAdapter {

    private Context context;
    private List<Leave> leaveList;

    public LeaveAdapter(List<Leave> leaveList, Context context) {
        this.leaveList = leaveList;
        this.context = context;
    }

    @Override
    public int getCount() {
        return leaveList.size();
    }

    @Override
    public Leave getItem(int position) {
        return leaveList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        Leave leaveItem = getItem(position);
        final ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_leave, null);
            viewHolder = new ViewHolder();
            viewHolder.tv_date = (TextView) convertView.findViewById(R.id.tv_date);
            viewHolder.tv_type = (TextView) convertView.findViewById(R.id.tv_type);
            viewHolder.tv_introduction = (TextView) convertView.findViewById(R.id.tv_introduction);
            viewHolder.tv_status = (TextView) convertView.findViewById(R.id.tv_status);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.tv_date.setText(leaveItem.getApplyDate() + " " + leaveItem.getStartEndTime());
        viewHolder.tv_type.setText(leaveItem.getType());
        viewHolder.tv_introduction.setText(leaveItem.getIntroduction());
        viewHolder.tv_status.setText(leaveItem.getStatus());

        return convertView;
    }

    class ViewHolder {
        TextView tv_date;
        TextView tv_type;
        TextView tv_status;
        TextView tv_introduction;
    }
}
